<%@page import="org.sysmhg.util.Constants"%>
<script type="text/javascript">

Ext.namespace('Ext.org.sysmhg.base.customer');

Ext.org.sysmhg.base.customer.CustomerFormPanel = function(config) {
	var customerFormPanel = this;
	
	var customerFormRecord = Ext.data.Record.create([
	     {name:'customer_id', type:'int', mapping:'customer_id' }
	     ,{name:'company_id', type:'int' ,mapping:'company_id'}  
	     ,{name:'code', type:'string' ,mapping:'code' }  
	     ,{name:'name', type:'string' ,mapping:'name' }
	     ,{name:'comercial_name', type:'string' ,mapping:'comercial_name' }
	     ,{name:'discount', type:'float' ,mapping:'discount' }
	     ,{name:'is_active', type:'int' ,mapping:'is_active' }
	     ,{name:'created', type:'date' ,mapping:'created', dateFormat: 'Y-m-d H:i:s.u' }
	     ,{name:'observation', type:'string' ,mapping:'observation' }
	]);
	
	var customerJsonReader = new Ext.data.JsonReader({
			root: "data"
		},customerFormRecord
	);
	
	this.hdnCustomerId = new Ext.form.Hidden({	
		name:'customer_id'
	});
	
	this.cboCompanyId = new Ext.form.ComboBox({
		fieldLabel: 'Company',
		valueField: 'company_id',
		displayField: 'name',
		hiddenName : 'company_id', 
		triggerAction: 'all',
		emptyText:'Seleccione',
		allowBlank :false,
		store:new Ext.data.JsonStore({													
            root  : "data",
            fields: [{
		    	name:'company_id',
				type:'int'
			},{
				name:'name',
				type:'string'
			}],				    							   
	        url: 'Company.htm?action=getCompanies',
	        autoLoad: true,
	        listeners: {
            	single: true
            	,load: function(){
                    customerFormPanel.cboCompanyId.setValue(customerFormPanel.cboCompanyId.value);
                }
            }
            
	    })
	});
	
	this.txtCode = new Ext.form.TextField({
		fieldLabel: 'Code',
        name: 'code',
        allowBlank :false,
        width: 200
	});
	
	this.txtName = new Ext.form.TextField({
		fieldLabel: 'Name',
        name: 'name',
        width: 200
	});
	
	this.txtComercialName = new Ext.form.TextField({
		fieldLabel: 'Comercial Name',
        name: 'comercial_name',
        width: 200
	});
	
	this.txtDiscount = new Ext.form.NumberField({
		fieldLabel: 'Discount',
        name: 'discount',
        width: 200
	});
	
	this.chkIsActive = new Ext.form.Checkbox({
		fieldLabel:"Active",
		name: 'is_active',
		checked : true,
		inputValue : '1'
	});
	
	this.txtCreated = new Ext.form.DateField({
		width: 100,
		fieldLabel: 'Created',
		name:'created',
		format: 'd/m/Y',
		allowBlank :false
	});	
	
	this.txtObservation = new Ext.form.TextArea({
		fieldLabel:"Observation",
		name: 'observation',
		width: 200
	});
	
	config.items = 	[
        this.cboCompanyId,
		this.txtCode,
		this.txtDiscount,
		this.chkIsActive,
       	this.txtComercialName,
		this.txtName,
		this.txtCreated,		
		this.txtObservation,
		this.hdnCustomerId			   
	];
	/*
	config.items = 	[
					   {	
						layout: 'column',
						items: [{
							columnWidth:.5,
	                		layout: 'form',
	                		items: [
	                			this.cboCompany,
								this.txtCode,
								this.txtDiscount,
								this.chkIsActive,
								{
									columnWidth:1.0,
			                		layout: 'form',
			                		items: [
			                			this.txtObservation
			                		]
								}
								
	                		]
						}, {
							columnWidth:.5,
					        layout: 'form',
					        items: [
					        	this.txtComercialName,
								this.txtName,
								this.txtCreated
					        ]
						}]
					}
	];
	*/
	config.reader = customerJsonReader;
	
	Ext.org.sysmhg.base.customer.CustomerFormPanel.superclass.constructor.call(this, config);	
}

Ext.extend(Ext.org.sysmhg.base.customer.CustomerFormPanel, Ext.form.FormPanel, {		
    labelWidth : 100//,
    ,layout : 'form'
    ,labelAlign : 'right'
    ,frame:true
});

</script>
